﻿package mortal.game.view.nationalDayAct
{
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class nationalDayActController extends Controller
    {
        private var _module:nationalDayActModule;
        private var _isEffectFlag:Boolean = false;

        public function nationalDayActController()
        {
            return;
        }// end function

        override protected function initView() : IView
        {
            if (this._module == null)
            {
                this._module = new nationalDayActModule();
                this._module.addEventListener(WindowEvent.SHOW, this.onShow);
                this._module.addEventListener(WindowEvent.CLOSE, this.onClose);
            }
            return this._module;
        }// end function

        private function ShowIcon(param1:Object = null) : void
        {
            var _loc_2:* = nationalDayActIcon.instance.isHide;
            if (nationalDayActUtil.checkCanOpen())
            {
                if (_loc_2)
                {
                    nationalDayActIcon.instance.show();
                    if (!this._isEffectFlag)
                    {
                        nationalDayActIcon.instance.playEffect();
                    }
                }
            }
            else if (!_loc_2)
            {
                nationalDayActIcon.instance.hide();
            }
            return;
        }// end function

        private function onRoleLevelUpdate(param1:Object) : void
        {
            this.ShowIcon();
            return;
        }// end function

        private function onShow(event:WindowEvent) : void
        {
            return;
        }// end function

        private function onClose(event:WindowEvent) : void
        {
            return;
        }// end function

        override protected function initServer() : void
        {
            Dispatcher.addEventListener(EventName.NationalDayActShow, this.onViewShow);
            NetDispatcher.addCmdListener(ServerCommand.RoleLevelUpdate, this.onRoleLevelUpdate);
            Dispatcher.addEventListener(EventName.LoginGameSuccess, this.ShowIcon);
            NetDispatcher.addCmdListener(ServerCommand.NewDayUpdate, this.onNewDayUpdate);
            return;
        }// end function

        private function onNewDayUpdate(param1:Object = null) : void
        {
            this.ShowIcon();
            var _loc_2:* = nationalDayActIcon.instance.isHide;
            if (this._module && !this._module.isHide && _loc_2)
            {
                this._module.hide();
            }
            return;
        }// end function

        private function onViewShow(event:DataEvent) : void
        {
            this._isEffectFlag = true;
            nationalDayActIcon.instance.stopEffect();
            if (!isViewShow)
            {
                view.show();
            }
            else
            {
                view.hide();
            }
            return;
        }// end function

    }
}
